package cn.tedu;
// InputStream  抽象类
import java.io.*;

public class Test2 {
    public static void main(String[] args) throws IOException {
        method();
        //method2();
        method3();
    }
    private static void method() throws IOException {
        InputStream in=new FileInputStream("F:\\ideaIO\\1.txt");
        //System.out.println(in.read());
        //System.out.println(in.read());;
        //System.out.println(in.read());;
        //System.out.println(in.read());;
        //System.out.println(in.read());;
        //System.out.println(in.read());;
       int date=0;
       while((date=in.read())!=-1){
           System.out.println(date);
       }//规范写法
       /* int date=in.read();
        while(date!=-1){
            System.out.println(date);
        } */ //出错   死循环
       /* while(in.read()!=-1){
            System.out.println(in.read());
        }*/    //出错
        in.close();//可以不写 // 关闭此输入流并释放与该流关联的所有系统资源
        //资源关闭后,再读取,报错 java.io.IOException: Stream Closed
        //System.out.println(in.read());;
    }
    private static void method2() throws FileNotFoundException {
        //File f=new File("");
       // InputStream in=new FileInputStream(f);
        InputStream in=new FileInputStream(new File(""));
    }
    private static void method3() throws IOException {
        InputStream in=new BufferedInputStream(new FileInputStream ("F:\\ideaIO\\1.txt"));
        int a=0;
        while((a=in.read())!=-1){
            System.out.println(a);
        }
        in.close();//可以不写
    }

}
